package com.edu.study.base.StuQuestionBelongtoRelation.controller;

import com.edu.study.base.StuQuestionBelongtoRelation.domain.StuQuestionBelongtoRelation;
import com.edu.study.base.StuQuestionBelongtoRelation.service.IStuQuestionBelongtoRelationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题库归属关系Controller
 *
 * @author jjt
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/belongTo/relation")
public class StuQuestionBelongtoRelationController extends BaseController
{
    @Autowired
    private IStuQuestionBelongtoRelationService stuQuestionBelongtoRelationService;

    /**
     * 查询题库归属关系列表
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(StuQuestionBelongtoRelation stuQuestionBelongtoRelation)
    {
        startPage();
        List<StuQuestionBelongtoRelation> list = stuQuestionBelongtoRelationService.selectStuQuestionBelongtoRelationList(stuQuestionBelongtoRelation);
        return getDataTable(list);
    }

    /**
     * 导出题库归属关系列表
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:export')")
    @Log(title = "题库归属关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StuQuestionBelongtoRelation stuQuestionBelongtoRelation)
    {
        List<StuQuestionBelongtoRelation> list = stuQuestionBelongtoRelationService.selectStuQuestionBelongtoRelationList(stuQuestionBelongtoRelation);
        ExcelUtil<StuQuestionBelongtoRelation> util = new ExcelUtil<StuQuestionBelongtoRelation>(StuQuestionBelongtoRelation.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 获取题库归属关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(stuQuestionBelongtoRelationService.selectStuQuestionBelongtoRelationById(id));
    }

    /**
     * 新增题库归属关系
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:add')")
    @Log(title = "题库归属关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuQuestionBelongtoRelation stuQuestionBelongtoRelation)
    {
        return toAjax(stuQuestionBelongtoRelationService.insertStuQuestionBelongtoRelation(stuQuestionBelongtoRelation));
    }

    /**
     * 修改题库归属关系
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:edit')")
    @Log(title = "题库归属关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuQuestionBelongtoRelation stuQuestionBelongtoRelation)
    {
        return toAjax(stuQuestionBelongtoRelationService.updateStuQuestionBelongtoRelation(stuQuestionBelongtoRelation));
    }

    /**
     * 删除题库归属关系
     */
    @PreAuthorize("@ss.hasPermi('belongTo:relation:remove')")
    @Log(title = "题库归属关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(stuQuestionBelongtoRelationService.deleteStuQuestionBelongtoRelationByIds(ids));
    }
}
